import { post,get, post_json } from '@/http/axios'
export default {
  namespaced: true,
  state: {
      //栏目数据
        categoryData:[],
        categoryId:[],
  },
  getters:{
      icon_CATEGORYDATA(state){
        return state.categoryData.reverse().slice(0,8);
      }
  },
  mutations: {
        SET_CATEGORYDATA(state,data){
            state.categoryData = data;
        },

        SET_BADGE(state,data){
          
          state.categoryData.some((productCategory,i) => {
            if(productCategory.id == data.productCategoryId){
              state.categoryData[i].badge = data.badge;
              if(data.badge == 0){
                state.categoryData[i].badge = ""
              }
              return true;
            }
          })
          state.categoryData.push()
        },
        SET_CATEGORYID(state,data){
            state.categoryId = data
            
        }
  },
  actions: {

    async getCategoryDataVuex({commit},param){
        //发送网络请求
        let res = await get('/productCategory/pageQuery',param)      
        //提交
        commit('SET_CATEGORYDATA',res.data.data.list)
      //  console.log(res.data.data.list)
    },
     
    async findCategoryIdByName({commit},param){
      //发送网络请求
      let res = await get('/productCategory/pageQuery',param)      
      //提交
      commit('SET_CATEGORYID',res.data.data.list)
   
  },
    
  }
}